package com.biz.user.controller;

import com.biz.bean.Result;
import com.biz.user.entity.dto.UserDto;
import com.biz.user.entity.req.*;
import com.biz.user.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author liuxi
 * @Date 2024/4/17
 **/
@RestController
@RequestMapping("/user")
public class UserController {
    
    @Autowired
    private UserService userService;
    
    @PostMapping
    public Result addUser(@RequestBody UserReq userReq) {
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userReq, userDto);
        return Result.ok(userService.addUser(userDto));
    }

    @DeleteMapping("/{id}")
    public Result deleteUser(@PathVariable Integer id) {
        return Result.ok(userService.deleteUser(id));
    }

    @GetMapping
    public Result getPage(@RequestBody UserPageReq userPageReq) {
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userPageReq, userDto);
        return Result.ok(userService.getUserPage(userDto));
    }

}
